<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>Computer</title>
</head>
<style>

</style>
<body>
<div class="computer">
    <h1 align="center">计算器</h1>
    num1: <input type="text" name="num1" id="num1"></br>
    num2: <input type="text" name="num2" id="num2"></br>
    <button onclick="computer('+')">+</button>
    <button onclick="computer('-')">-</button>
    <button onclick="computer('*')">*</button>
    <button onclick="computer('/')">/</button>
    </br>
    结果: <input type="text" name="result" id="result">
</div>

</body>
<script>
    function computer(fuhao){
        let num1 = parseInt(document.getElementById("num1").value);
        let num2 = parseInt(document.getElementById("num2").value);
        let result;
        switch (fuhao){
            case '+':
            result=num1+num2;
            break;
            case '-':
                result=num1-num2;
                break;
            case '*':
                result=num1*num2;
                break;
            case '/':
                if (num2==0) {
                    alert("除数不能为0");
                    return;
                }
                result=num1/num2;
                break;
        }
        let ObjResult = document.getElementById("result");
        ObjResult.value = result

    }
</script>
</html>